<?php
class Dayoff_m extends MY_Model{
	
	
	function __construct(){
		parent::__construct();
		$this->_table = 'erp_dayoff';
	}
	
	function list_short(){
		$tmp = parent::get_all();
		//print_r($tmp);exit;
		$result = array();
		foreach($tmp as $item){
			//$item->value = date("m-d",strtotime($item->value));
			//$d = new DateTime( date('m-d'.$micro,$t) );
			$obj = new stdClass();
			$obj = $item;
			$result[] = $obj;
		}
		return $result;
	}
	
	function add($data){
		$value = strtotime($data['value']);
		$data['value'] = date("Y-m-d",$value);
		$data['delete']	= 1;
//		print_r($data);exit;
		parent::insert($data);
		
	}
	
	function single( $id ){
		$this->db->where('id',$id);
		return $this->db->get($this->_table)->row_array();
		
	}
	
	function update_single($id,$data){
		$value = strtotime($data['value']);
		$data['value'] = date("Y-m-d",$value);
		$data['delete']	= 1;
		parent::update($id,$data);
	}
	
	public function  get_all(){
		$result = parent::get_all();
		
		foreach($result as $item){
			$item->value = strtotime(date("Y-").$item->value);
		}
		//print_r($result);exit;
		return $result;
	}
	
	public function insert($model){
		$value = strtotime($model['value']);
		$model['value'] = date("m-d",$value);
		return parent::insert($model);
	}
	public function update($id,$model){
		//print_r($model);exit;
		$value = strtotime($model['value']);
		$model['value'] = date("m-d",$value);
		return parent::update($id,$model);
	}
	
	public function get($id){
		$model = parent::get($id);
		$value = strtotime(date("Y-").$model->value);
		$model->value = date("d-m-Y",$value);
		return $model;
	}
	
}